<?php

namespace iBrand\Component\Refund\Observers;

use iBrand\Component\Refund\Models\Refund;
use DB;

class RefundObserver
{
    /**
     * 监听订单退货(物理)删除事件。
     *
     * @param  Refund  $refund
     * @return void
     */
    public function deleted(Refund $refund)
    {
        try {
            DB::beginTransaction();
            if (!$refund::withTrashed()->find($refund->id)) {
                $refund->logs()->withTrashed()->forceDelete();
            }
            DB::commit();
        } catch (\Exception $exception) {
            DB::rollBack();
            \Log::error($exception->getMessage());
        }

    }
}